﻿using DevExpress.Pdf.Native.BouncyCastle.Asn1.X509;
using DevExpress.XtraEditors;
using DevExpress.XtraRichEdit.Model;
using FuelDXApplication1.Entity;
using FuelDXApplication1.Havebeen;
using FuelDXApplication1.HqhWinform;
using FuelDXApplication1.MksWinform;
using FuelDXApplication1.TmzWinform;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Controls.Ribbon;
using System.Windows.Forms;
using static DevExpress.Xpo.Helpers.AssociatedCollectionCriteriaHelper;

namespace FuelDXApplication1
{
    public partial class Form1 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        private bool isFormLoaded = false; // 标志，用于判断表单是否已经加载
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 参数燃料填报
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void navBarItem1_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            FuelAdd fuelAdd = new FuelAdd();
            fuelAdd.Show();
        }
        /// <summary>
        /// 待上报
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void navBarItem2_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            // 如果panel2中已经有控件，先移除它
            if (panel2.Controls.Count > 0)
            {
                panel2.Controls.Clear();
            }

            ToBeEscalated form1 = new ToBeEscalated();
            form1.TopLevel = false;
            form1.Dock = DockStyle.Fill;
            form1.FormBorderStyle = FormBorderStyle.None;
            panel2.Controls.Add(form1);
            form1.Show();
            isFormLoaded = true;
        }
        /// <summary>
        /// 补传待上报
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void navBarItem3_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            // 如果panel2中已经有控件，先移除它
            if (panel2.Controls.Count > 0)
            {
                panel2.Controls.Clear();
            }

            //    XtraForm1 form1 = new XtraForm1();
            //    form1.TopLevel = false;
            //    form1.Dock = DockStyle.Fill;
            //    form1.FormBorderStyle = FormBorderStyle.None;
            //    panel2.Controls.Add(form1);
            //    form1.Show();
            //}
            SupplementaryTransmission form1 = new SupplementaryTransmission();
            form1.TopLevel = false;
            form1.Dock = DockStyle.Fill;
            form1.FormBorderStyle = FormBorderStyle.None;
            panel2.Controls.Add(form1);
            form1.Show();
        }
        /// <summary>
        /// 已上报
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void navBarItem4_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            // 如果panel2中已经有控件，先移除它
            if (panel2.Controls.Count > 0)
            {
                panel2.Controls.Clear();
            }

            AlreadyReport form1 = new AlreadyReport();
            form1.TopLevel = false;
            form1.Dock = DockStyle.Fill;
            form1.FormBorderStyle = FormBorderStyle.None;
            panel2.Controls.Add(form1);
            form1.Show();
        }
        /// <summary>
        /// 已修改未上报
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void navBarItem5_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            // 如果panel2中已经有控件，先移除它
            if (panel2.Controls.Count > 0)
            {
                panel2.Controls.Clear();
            }

            AlreadyModified form1 = new AlreadyModified();
            form1.TopLevel = false;
            form1.Dock = DockStyle.Fill;
            form1.FormBorderStyle = FormBorderStyle.None;
            panel2.Controls.Add(form1);
            form1.Show();
        }

        /// <summary>
        /// 日期同步
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void navBarItem12_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            //从后端获取数据
            var iflist = await HttpClientHelper.RequestUrl<string, ApiResult<List<Holiday>>>("https://localhost:44341/", "api/app/fuel-synchronization/hoiaday", MethodType.Get);
            //数据
            var holidaylist = iflist.Data;

            List<Holiday> entitiesToInsert = new List<Holiday>();

            foreach (var item in holidaylist)
            {
                var vehicinfor = new Holiday { HolidayName = item.HolidayName, StartDate = item.StartDate, EndDate = item.EndDate };

                entitiesToInsert.Add(vehicinfor);

            }
            int result = await DBHelper.InsertRange(entitiesToInsert);

            if (result > 0)
            {
                MessageBox.Show("同步成功");
            }
        }



        //private void ShowPage()
        //{

        //    //FuelAdd fuelAdd = new FuelAdd();
        //    //fuelAdd.Show();
        //    XtraForm1 toBeEscalated = new XtraForm1();
        //    toBeEscalated.TopLevel = false;
        //    toBeEscalated.Dock = DockStyle.Fill;
        //    toBeEscalated.FormBorderStyle = FormBorderStyle.None;
        //    panel2.Controls.Add(toBeEscalated);
        //    toBeEscalated.Show();
        //}




        //private void panelControl1_Paint(object sender, PaintEventArgs e)
        //{

        //}


        /// <summary>
        /// 已修改未上报
        /// </summary>
        /// <param name = "sender" ></ param >
        /// < param name="e"></param>
        //private void navBarItem5_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        //{

    }

    //    private  void ShowPage()
    //    {
    //        //从后端获取数据
    //        var iflist = await HttpClientHelper.RequestUrl<string, ApiResult<List<FuelParameters>>>("https://localhost:44341/", "api/app/fuel-synchronization/fuel-info", MethodType.Get);
    //        //数据
    //        var iflistdast = iflist.Data;

    //        List<FuelParameters> entitiesToInsert = new List<FuelParameters>();

    //        foreach (var item in iflistdast)
    //        {
    //            var vehicinfor = new FuelParameters { FuelTypeId = item.FuelTypeId, TransmissionTypeId = item.TransmissionTypeId, EngineModel = item.EngineModel, FuelParametersName = item.FuelParametersName, NumberOfCylinders = item.NumberOfCylinders, FuelConsumptionInSuburbanConditions = item.FuelConsumptionInSuburbanConditions, CombinedOperatingConditionC02Emissions = item.CombinedOperatingConditionC02Emissions, BanSuQiDang = item.BanSuQiDang, RatedPower = item.RatedPower, NetPower = item.NetPower, AutomotiveEnergyTechnology = item.AutomotiveEnergyTechnology, iNfoOther = item.iNfoOther, FuelConsumptionInUrbanConditions = item.FuelConsumptionInUrbanConditions, FuelConsumptionUnderComprehensiveOperatingConditions = item.FuelConsumptionUnderComprehensiveOperatingConditions };

    //            entitiesToInsert.Add(vehicinfor);

    //        }
    //        int result = await DBHelper.InsertRange(entitiesToInsert);
    //    }


    //        if (result > 0)
    //        {
    //            MessageBox.Show("同步成功");
    //        }

    //    }
    //    /// <summary>
    //    /// 日期同步
    //    /// </summary>
    //    /// <param name="sender"></param>
    //    /// <param name="e"></param>
    //    private async void navBarItem12_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
    //    {
    //        //从后端获取数据
    //        var iflist = await HttpClientHelper.RequestUrl<string, ApiResult<List<Holiday>>>("https://localhost:44341/", "api/app/fuel-synchronization/hoiaday", MethodType.Get);
    //        //数据
    //        var holidaylist = iflist.Data;

    //        List<Holiday> entitiesToInsert = new List<Holiday>();

    //        foreach (var item in holidaylist)
    //        {
    //            var vehicinfor = new Holiday { HolidayName = item.HolidayName, StartDate = item.StartDate, EndDate = item.EndDate };

    //            entitiesToInsert.Add(vehicinfor);

    //        }
    //        int result = await DBHelper.InsertRange(entitiesToInsert);

    //        if (result > 0)
    //        {
    //            MessageBox.Show("同步成功");
    //        }
    //    }
    //    /// <summary>
    //    /// 燃料参数同步
    //    /// </summary>
    //    /// <param name="sender"></param>
    //    /// <param name="e"></param>
    //    private async void navBarItem11_LinkClicked_1(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
    //    {
    //        //从后端获取数据
    //        var iflist = await HttpClientHelper.RequestUrl<string, ApiResult<List<FuelParameters>>>("https://localhost:44341/", "api/app/fuel-synchronization/fuel-info", MethodType.Get);
    //        //数据
    //        var iflistdast = iflist.Data;

    //        List<FuelParameters> entitiesToInsert = new List<FuelParameters>();

    //        foreach (var item in iflistdast)
    //        {
    //            var vehicinfor = new FuelParameters { FuelTypeId = item.FuelTypeId, TransmissionTypeId = item.TransmissionTypeId, EngineModel = item.EngineModel, FuelParametersName = item.FuelParametersName, NumberOfCylinders = item.NumberOfCylinders, FuelConsumptionInSuburbanConditions = item.FuelConsumptionInSuburbanConditions, CombinedOperatingConditionC02Emissions = item.CombinedOperatingConditionC02Emissions, BanSuQiDang = item.BanSuQiDang, RatedPower = item.RatedPower, NetPower = item.NetPower, AutomotiveEnergyTechnology = item.AutomotiveEnergyTechnology, iNfoOther = item.iNfoOther, FuelConsumptionInUrbanConditions = item.FuelConsumptionInUrbanConditions, FuelConsumptionUnderComprehensiveOperatingConditions = item.FuelConsumptionUnderComprehensiveOperatingConditions };

    //            entitiesToInsert.Add(vehicinfor);

    //        }
    //        int result = await DBHelper.InsertRange(entitiesToInsert);

    //        if (result > 0)
    //        {
    //            MessageBox.Show("同步成功");
    //        }
    //    }
    //    /// <summary>
    //    /// 小登录页面
    //    /// </summary>
    //    /// <param name="sender"></param>
    //    /// <param name="e"></param>
    //    private async void navBarItem12_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
    //    {
    //        //从后端获取数据
    //        var iflist = await HttpClientHelper.RequestUrl<string, ApiResult<List<Holiday>>>("https://localhost:44341/", "api/app/fuel-synchronization/hoiaday", MethodType.Get);
    //        //数据
    //        var holidaylist = iflist.Data;

    //        List<Holiday> entitiesToInsert = new List<Holiday>();

    //        foreach (var item in holidaylist)
    //        {
    //            var vehicinfor = new Holiday { HolidayName = item.HolidayName, StartDate = item.StartDate, EndDate = item.EndDate };

    //            entitiesToInsert.Add(vehicinfor);


    //    }




    //    }

        /// <summary>
        /// 燃料参数同步
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void navBarItem11_LinkClicked_1(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            //从后端获取数据
            var iflist = await HttpClientHelper.RequestUrl<string, ApiResult<List<FuelParameters>>>("https://localhost:44341/", "api/app/fuel-synchronization/fuel-info", MethodType.Get);
            //数据
            var iflistdast = iflist.Data;

            List<FuelParameters> entitiesToInsert = new List<FuelParameters>();

            foreach (var item in iflistdast)
            {
                var vehicinfor = new FuelParameters { FuelTypeId = item.FuelTypeId, TransmissionTypeId = item.TransmissionTypeId, EngineModel = item.EngineModel, FuelParametersName = item.FuelParametersName, NumberOfCylinders = item.NumberOfCylinders, FuelConsumptionInSuburbanConditions = item.FuelConsumptionInSuburbanConditions, CombinedOperatingConditionC02Emissions = item.CombinedOperatingConditionC02Emissions, BanSuQiDang = item.BanSuQiDang, RatedPower = item.RatedPower, NetPower = item.NetPower, AutomotiveEnergyTechnology = item.AutomotiveEnergyTechnology, iNfoOther = item.iNfoOther, FuelConsumptionInUrbanConditions = item.FuelConsumptionInUrbanConditions, FuelConsumptionUnderComprehensiveOperatingConditions = item.FuelConsumptionUnderComprehensiveOperatingConditions };

                entitiesToInsert.Add(vehicinfor);

            }
            int result = await DBHelper.InsertRange(entitiesToInsert);
        }
    }
}


